#pragma once

#include <istream>
#include <ostream>
#include "MyersAlgorythm.h"

const char add_string = '+';
const char delete_string = '-';
const char do_nothing =' ';

std::vector<std::string> ReadSequence(std::istream& input) {
    
    std::string string;
    std::vector<std::string> sequence;

    while (getline(input, string)) {
        sequence.push_back(string);
    }

    return sequence;
}

void PrintSequenceOfChanges(const std::vector<std::string>& first_sequence_string, 
		const std::vector<std::string>& second_sequence_string, std::vector<Point>& common_strings_numbers, std::ostream& output) {

    int previous_common_string_number_x = -1;
    int previous_common_string_number_y = -1;

    Point last_common_point(first_sequence_string.size(), second_sequence_string.size());
    common_strings_numbers.push_back(last_common_point);

    for (int i = 0; i < common_strings_numbers.size(); ++i) {
        int next_common_string_number_x = common_strings_numbers[i].x_;
        int next_common_string_number_y = common_strings_numbers[i].y_;

        if ((next_common_string_number_x - previous_common_string_number_x ==
               next_common_string_number_y - previous_common_string_number_y) 
                   && (next_common_string_number_x - previous_common_string_number_x == 0)) {

            previous_common_string_number_x = next_common_string_number_x;
            previous_common_string_number_y = next_common_string_number_y;
            continue;
        }

        if (next_common_string_number_x - previous_common_string_number_x > 0) {
            for (int j = 1; j < next_common_string_number_x - previous_common_string_number_x; ++j) {
                output << delete_string << first_sequence_string[previous_common_string_number_x + j] << '\n';
            }
        }

        if (next_common_string_number_y - previous_common_string_number_y > 0) {
            for (int j = 1; j < next_common_string_number_y - previous_common_string_number_y; ++j) {
                output << add_string << second_sequence_string[previous_common_string_number_y + j] << '\n';
            }
        }

        if (next_common_string_number_x < first_sequence_string.size()) {
            output << do_nothing << first_sequence_string[next_common_string_number_x] << '\n';
        }
        
        previous_common_string_number_x = next_common_string_number_x;
        previous_common_string_number_y = next_common_string_number_y;
   }
}

